<template>
	<view style="padding: 15px 30rpx;">
		<view class="totle">共{{totle}}人</view>
		<view class="list" v-for="(item,index) in list" :key="index">
			<view class="left">
				<text>{{item.nickName}}</text>
				<text class="phone">{{item.phone}}</text>
			</view>
			<button class="takephone" plain size="mini" @click="TakePhone(item.phone)">立即联系<uni-icons type="phone" size="16" color="#00B5DD"></uni-icons></button>
		</view>
	</view>
</template>

<script>
	import {queryAccountList} from "@/api/user.js";
	import permision from "@/js_sdk/wa-permission/permission.js"
	export default {
		data() {
			return {
				parmas:'',
				list: [],
				totle:'',
			}
		},
		onLoad:function(option){
			this.parmas = option.id
			this.queryAccountList(this.parmas)
		},
		onPullDownRefresh() {
			this.queryAccountList(this.parmas)
			uni.stopPullDownRefresh();
		},
		onReady() {
			if(this.parmas == 'role004'){
				uni.setNavigationBarTitle({
					title: '农技员列表'
				});
			}else if(this.parmas == 'role005'){
				uni.setNavigationBarTitle({
					title: '帮扶员列表'
				});
			}else if(this.parmas == 'role006'){
				uni.setNavigationBarTitle({
					title: '宣传员列表'
				});
			}else if(this.parmas == 'role007'){
				uni.setNavigationBarTitle({
					title: '供销员列表'
				});
			}else if(this.parmas == 'role008'){
				uni.setNavigationBarTitle({
					title: '信贷员列表'
				});
			}
			
		},
		methods: {
			async queryAccountList(options){
				const res = await queryAccountList(options);
				if(res.success){
					this.list = res.returnObj
					console.log("联系人",this.list)
					if(this.list != []){
						this.totle = this.list.length;
					}else{
						this.totle = '0'
					}
					console.log(this.totle)
				}
			},
			TakePhone(e) {
				permision.requestAndroidPermission('android.permission.CALL_PHONE').then((res)=>{
					console.log("authres",res)
					if(res == 1){
						uni.makePhoneCall({
							phoneNumber: e
						});
					}else{
						permision.gotoAppPermissionSetting()
					}
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.totle{
		color: #646A74;
	}
.list{
	display: flex;
	flex-flow: row nowrap;
	justify-content: space-between;
	align-items: center;
	padding:12px 0;
	
	.left{
		flex-grow: 1;
	}
	
	.left text{
		display: block;
		font-size: 32rpx;
		line-height: 24px;
		color: #283241;
	}
	.left text.phone{
		color: #9498A0;
		font-size: 28rpx;
	}
	
	.takephone{
		border: 1px solid #00B5DD;
		color: #00B5DD;
		border-radius: 4px;
		height: 38px;
		line-height: 38px;
	}
}
</style>
